import java.util.*;

/**
 * Created by qtbui on 2017/9/21.
 */

class ListNode
{
    int val;
    ListNode next;
    ListNode(int x)
    {
        val = x;
        next=null;
    }
}

class Solution
{
    public ListNode deleteDuplicates(ListNode head)
    {
        Set<Integer> setVal=new TreeSet<Integer>();
        ListNode p = head;
        while(p!=null)
        {
            setVal.add(p.val);
            p=p.next;
        }

        ListNode newHead=new ListNode(0);
        p=newHead;
        for(Iterator<Integer> itor=setVal.iterator();itor.hasNext();)
        {
            p.next=new ListNode(itor.next());
            p=p.next;
        }
        return newHead.next;
    }
}

public class test
{
    public static void main(String[] args)
    {
        ListNode a=new ListNode(1);
        ListNode b=new ListNode(2);
        a.next=b;

        new Solution().deleteDuplicates(a);
    }
}
